<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let arr = ['张三', '李四', '王五', '赵六', '田七']
    while (flag = 1) {
      let index = Math.floor(Math.random() * arr.length)
      document.write(arr[index] + '<br>')
      arr.splice(index, 1)
      console.log(arr)
      if (arr.length == 0) {
        document.write('没有数据了')
        break
      }
    }
    // for (let i = 0; i < arr.length; i++) { // let index=Math.floor(Math.random() * arr.length) 
    // document.write(arr[index])
    // arr.splice(index, 1)
    // console.log(arr)
    // if (arr.length==0) {
    // alert('没有数据了')
    // break
    // }
    // } 
  </script>

</body>

</html>